﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Data.Common;
using ChBusiness;

namespace ExtBusiness.Menu
{
    public class ClsAppearOaMenu
    {
        private Database dbGloab = BasicOperate.CreateNetOfficeDataBase();

        /// <summary>
        /// 生成父级菜单
        /// </summary>
        /// <returns></returns>
        public DataTable GenerateParentMenu()
        {
            string strSql = @"select a.* from xt_menu_parent a order by show_no";
            DataTable dtReturn = dbGloab.ExecuteDataSet(CommandType.Text,strSql).Tables[0];
            return dtReturn;
        }

        /// <summary>
        /// 生成子级菜单
        /// </summary>
        /// <param name="strParentId"></param>
        /// <returns></returns>
        public DataTable GenerateChildMenu(string strParentId,string userid)
        {
            string strSql = string.Format(@"select a.* from xt_menu_child a, xt_menu_parent b
                 where a.ancestor = b.menu_parent_id and a.ancestor = '{0}'
                 and  menu_child_id in(select menu_child_id from xt_group_menu where right_id in(select groupid
  from st_group a
 where a.groupid in
       (select gid
          from st_user_group
         where userid = '{1}')))                                     
                 order by a.show_no", strParentId,userid);
            DataTable dtReturn = dbGloab.ExecuteDataSet(CommandType.Text, strSql).Tables[0];
            return dtReturn;
        }

    }
}
